﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;

namespace BLL.Common
{
    /// <summary>
    /// 业务逻辑类CODE 的摘要说明。
    /// </summary>
    public class CODE
    {
        private readonly OracleDAL.Common.CODE dal = new OracleDAL.Common.CODE();
        public CODE()
        { }
        #region  成员方法
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string CODEID)
        {
            return dal.Exists(CODEID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Model.Common.CODE model)
        {
            dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Model.Common.CODE model)
        {
            dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(string CODEID)
        {

            dal.Delete(CODEID);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.Common.CODE GetModel(string CODEID)
        {

            return dal.GetModel(CODEID);
        }

        ///// <summary>
        ///// 得到一个对象实体，从缓存中。
        ///// </summary>
        //public Model.Common.CODE GetModelByCache(string CODEID)
        //{

        //    string CacheKey = "CODEModel-" + CODEID;
        //    object objModel = LTP.Common.DataCache.GetCache(CacheKey);
        //    if (objModel == null)
        //    {
        //        try
        //        {
        //            objModel = dal.GetModel(CODEID);
        //            if (objModel != null)
        //            {
        //                int ModelCache = LTP.Common.ConfigHelper.GetConfigInt("ModelCache");
        //                LTP.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
        //            }
        //        }
        //        catch{}
        //    }
        //    return (Model.Common.CODE)objModel;
        //}

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.Common.CODE> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Model.Common.CODE> DataTableToList(DataTable dt)
        {
            List<Model.Common.CODE> modelList = new List<Model.Common.CODE>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.Common.CODE model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.Common.CODE();
                    model.CODEID = dt.Rows[n]["CODEID"].ToString();
                    model.CODEVALUE = dt.Rows[n]["CODEVALUE"].ToString();
                    model.SORT = dt.Rows[n]["SORT"].ToString();
                    model.NODEID = dt.Rows[n]["NODEID"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  成员方法
    }
}

